<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/reset.css">
    <link rel="stylesheet" href="../font-awesome/css/all.css">
    <!-- 别忘了引用font-awesome -->
    <style>
        .box {
            width: 400px;
            margin: 30px auto;
        }

        input {
            padding-left: 10px;
            width: 200px;
            border-bottom: 1px solid black;
            /* 文本框默认有outline蓝色 */
        }

        i {
            font-size: 15px;
        }
    </style>
</head>

<body>
    <div class="box">
        <input type="password" id="pwd">
        <!-- 文字无法使用class更改，此处最好引用图片 -->
        <i class="fas fa-eye-slash" id="eye"></i>
    </div>
    <script>
        // 1.获取元素,使用  getElementById 来获取id速度更快
        var eye = document.getElementById('eye');
        var pwd = document.getElementById('pwd');
        // 2.注册事件处理程序
        var flag = 0;
        eye.onclick = function () {
            //点击一次之后，flag一定要变化
            if (flag == 0) {
                pwd.type = 'text';
                flag = 1;
            } else {
                pwd.type = 'password';

                flag = 0;
            }
        }
    </script>
</body>

</html>